import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';
import { IsString, MinLength, MaxLength, ValidateIf, IsUUID, IsNotEmpty } from 'class-validator';
import { CommentConstants } from '../../../constants/comment';

export class CreateCommentDto {
  @ApiProperty({ required: true, description: '文章Id' })
  @IsString({
    message: '无效的articleId',
  })
  @IsNotEmpty({ message: '文章id不能为空' })
  @IsUUID('4', { message: 'articleId UUID' })
  readonly articleId: string;

  @ApiPropertyOptional({ required: false, description: '评论父级Id' })
  @ValidateIf((o) => o.parentId !== undefined)
  @IsUUID('4', { message: '无效的parentId' })
  readonly parentId?: string;

  @ApiPropertyOptional({ required: false, description: '评论根Id' })
  @ValidateIf((o) => o.rootId !== undefined)
  @IsUUID('4', { message: '无效的rootId' })
  readonly rootId?: string;

  @ApiProperty({ required: true, description: '评论内容' })
  @MinLength(CommentConstants.MinContentLength, {
    message: '评论内容过少哦',
  })
  @MaxLength(CommentConstants.MaxContentLength, {
    message: '评论不能超过 $constraint1 个字符',
  })
  @IsString()
  @IsNotEmpty({ message: '评论内容不能为空' })
  readonly content: string;
}
